package com.anhry.app.safety.manage.enterprise.struts.action;

import java.util.Date;
import java.util.List;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.anhry.app.safety.manage.enterprise.bean.TbCorpInfo;
import com.anhry.app.safety.manage.enterprise.bean.TbCorpPerson;
import com.anhry.app.safety.manage.enterprise.bean.TbCorpType;
import com.anhry.app.safety.manage.enterprise.bean.vo.CorpBean;
import com.anhry.app.safety.manage.enterprise.struts.base.EnterpriseBaseAction;
import com.anhry.app.safety.manage.system.bean.TbUser;
import com.anhry.app.safety.manage.system.bean.TbUserDept;
import com.anhry.app.safety.util.Loggers;
import com.anhry.app.safety.util.Page;
import com.anhry.app.safety.util.PwdDigest;
import com.anhry.app.safety.util.Util;
import com.anhry.app.safety.util.bean.Permission;
import com.opensymphony.xwork2.ModelDriven;

/**
 * @date:2012-9-17
 * @remark:
 * @author:dongbin
 */

@Controller
@Scope("prototype")
@SuppressWarnings("unchecked")
public class CorpTwoAction  extends EnterpriseBaseAction implements ModelDriven<CorpBean>{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private CorpBean corpBean = new CorpBean();	//模型驱动
	private TbCorpPerson fzr;
	private TbCorpPerson aqfzr;
	private String fzrId;
	private String aqfzrId;
	
	/**
	 * 二级企业列表
	 * @return
	 */
	@Permission(module = "corptwo", permissionVaule = 1)
	public String list(){
		int rowCount = 0;
		int num = (this.num != null && !"".equals(this.num ))?Integer.parseInt(this.num ):1;
		int size = (this.size != null && !"".equals(this.size ))?Integer.parseInt(this.size ):10;
		try {
			TbUser user = (TbUser)this.contextPvd.getSessionAttr(Util.SESSION_ADMINUSER);
			String orderHql = "";//排序hql语句
			String hql = this.getQuaryHql();
			List objSize = this.enterprisService.getCorpList(hql,null,0,0);
			if(objSize != null && objSize.size() > 0){
				rowCount = Integer.parseInt(objSize.get(0).toString());
			}
			Page page = new Page(size,num,rowCount);
			this.setPage(page);
			this.setCorpList(this.enterprisService.getCorpList(hql,orderHql,page.getStartRow(),page.getSize()));
			
			this.setSdList(this.enterprisService.getSdList((List)this.contextPvd.getServletContextAttr(Util.QU_DEPT_LIST),user));
			this.setTypeList(this.enterprisService.getTypeList(user));
			this.setHyList((List)this.contextPvd.getServletContextAttr(Util.HY_DEPT_LIST));
			this.setResult("corpTwo_list");
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("enterprise: CorpTwoAction:list() 异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 企业添加页面
	 * @return
	 */
	@Permission(module = "corptwo", permissionVaule = 0)
	public String add(){
		try {
			TbUser user = (TbUser)this.contextPvd.getSessionAttr(Util.SESSION_ADMINUSER);
			this.setSdList(this.enterprisService.getSdList((List)this.contextPvd.getServletContextAttr(Util.QU_DEPT_LIST),user));
			this.setTypeList(this.enterprisService.getTypeList(user));
			this.setResult("corpTwo_add");
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("enterprise: CorpTwoAction:add() 异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 企业修改页面
	 * @return
	 */
	@Permission(module = "corptwo", permissionVaule = 2)
	public String update(){
		try {
			if(null!=this.corpId && this.corpId.length()>0){
				TbCorpInfo corp = this.enterprisService.getCorpById(corpId);
				if(null!=corp){
					this.setCorp(corp);
					TbUser user = (TbUser)this.contextPvd.getSessionAttr(Util.SESSION_ADMINUSER);
					this.setSdList(this.enterprisService.getSdList((List)this.contextPvd.getServletContextAttr(Util.QU_DEPT_LIST),user));
					this.setTypeList((List)this.contextPvd.getServletContextAttr(Util.MAX_CORP_TYPE));
					this.setFzr(this.enterprisService.getCorpPer(this.corpId, "2"));
					this.setAqfzr(this.enterprisService.getCorpPer(this.corpId, "3"));
					this.setResult("corpTwo_update");
					return SUCCESS;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("enterprise: CorpTwoAction:add() 异常："+e.getMessage());
		}
		this.setTip(Util.NOTIP);
		return ERROR;
	}
	
	/**
	 * 企业添加保存
	 * @return
	 */
	public String saveOrUpdate(){
		try {
			TbUserDept county = null;
			TbUserDept unit = null;
			TbUserDept dept = null;
			TbCorpType maxType = null;
			TbCorpType minType = null;
			TbUser user = (TbUser)this.contextPvd.getSessionAttr(Util.SESSION_ADMINUSER);
			if(null!=this.corpBean.getCountyId() && this.corpBean.getCountyId().length()>0){
				county = (TbUserDept)this.utilService.getObjectById(TbUserDept.class, Long.parseLong(this.corpBean.getCountyId()));
			}
			if(null!=this.corpBean.getUnitId() && this.corpBean.getUnitId().length()>0){
				unit = (TbUserDept)this.utilService.getObjectById(TbUserDept.class, Long.parseLong(this.corpBean.getUnitId()));
			}
			if(null!=this.corpBean.getDeptId() && this.corpBean.getDeptId().length()>0){
				dept = (TbUserDept)this.utilService.getObjectById(TbUserDept.class, Long.parseLong(this.corpBean.getDeptId()));
			}
			if(null!=this.corpBean.getMaxTypeId() && this.corpBean.getMaxTypeId().length()>0){
				maxType = (TbCorpType)this.utilService.getObjectById(TbCorpType.class, Long.parseLong(this.corpBean.getMaxTypeId()));
			}
			if(null!=this.corpBean.getMinTypeId() && this.corpBean.getMinTypeId().length()>0){
				minType = (TbCorpType)this.utilService.getObjectById(TbCorpType.class, Long.parseLong(this.corpBean.getMinTypeId()));
			}
			if(null!=this.corpId && this.corpId.length()>0){
				TbCorpInfo corp = (TbCorpInfo)this.utilService.getObjectById(TbCorpInfo.class, Long.parseLong(this.corpId));
				if(null!=corp){
					corp = this.saveCorp(corp);
					corp.setUpdateFalg("2");
					corp.setUpdateTime(new Date());
					corp.setUpdateUser(user.getUserName());//
					corp.setTbCounty(county);//
					corp.setTbStreet(unit);//
					corp.setTbVillage(dept);//
					this.utilService.update(corp);
					if(null!=this.fzrId && fzrId.length()>0){
						TbCorpPerson fzr = (TbCorpPerson)this.utilService.getObjectById(TbCorpPerson.class, Long.parseLong(this.fzrId));
						if(null!=fzr){
							fzr.setPerMobile(this.corpBean.getCorpFzrMobile());
							fzr.setPerName(this.corpBean.getCorpFzr());
							fzr.setPerPhone(this.corpBean.getCorpFzrPhone());
							fzr.setPerSex(this.corpBean.getCorpFzrSex());
							fzr.setPerDegree(this.corpBean.getCorpFzrDegree());
							fzr.setPerTraining(this.corpBean.getCorpFzrTraining());
							fzr.setPerWorkingYear(this.corpBean.getCorpFzrWorkingYear());
							fzr.setPerEmail(this.corpBean.getCorpFzrEmeail());
							this.utilService.update(fzr);
						}
					}
					if(null!=this.aqfzrId && aqfzrId.length()>0){
						TbCorpPerson aqr = (TbCorpPerson)this.utilService.getObjectById(TbCorpPerson.class, Long.parseLong(this.aqfzrId));
						if(null!=aqr){
							aqr.setPerMobile(this.corpBean.getCorpAqfzrMobile());
							aqr.setPerName(this.corpBean.getCorpAqfzr());
							aqr.setPerPhone(this.corpBean.getCorpAqfzrPhone());
							aqr.setPerSex(this.corpBean.getCorpAqfzrSex());
							aqr.setPerDegree(this.corpBean.getCorpAqfzrDegree());
							aqr.setPerTraining(this.corpBean.getCorpAqfzrTraining());
							aqr.setPerWorkingYear(this.corpBean.getCorpAqfzrWorkingYear());
							aqr.setPerEmail(this.corpBean.getCorpAqfzrEmeail());
							this.utilService.update(aqr);
						}
					}
					this.setTip("修改成功！");
					return this.update();
				}
			}else{
				if(null==this.corpBean.getCorpSjId() || "".equals(this.corpBean.getCorpSjId())){
					this.setTip("您未选择一级企业，请选择一级企业！");
					return this.add();
				}
				TbCorpInfo corp = new TbCorpInfo();
				corp = this.saveCorp(corp);
				corp.setCorpAddTime(new Date());
				corp.setCorpAddUser(user.getUserName());
				corp.setCorpAuditState("1");//审核状态
				//corp.setCorpCity();//所属市
				corp.setCorpLoginCount(0);
				//corp.setCorpProvince(corpProvince);//所属省
				corp.setCorpPwd(PwdDigest.passwordDigest("666666"));
				corp.setCorpPwd2("666666");
				corp.setIsDele("0");
				corp.setUpdateFalg("1");
				corp.setUpdateTime(new Date());
				corp.setUpdateUser(user.getUserName());//
				corp.setTbCorpType(maxType);//企业类型大类
				corp.setTbCorpTypeMin(minType);//企业类型小类
				corp.setTbCounty(county);//县(市、区)、开发区
				corp.setTbStreet(unit);//乡镇
				corp.setTbVillage(dept);//村社区
				corp.setCorpSize("2");
				corp.setCorpSjId(Long.parseLong(this.corpBean.getCorpSjId()));
				corp.setCorpSjName(this.corpBean.getCorpSjName());
				this.utilService.save(corp);
				
				String corpfr = this.corpBean.getCorpFr();//法人
				if(null!=corpfr && corpfr.length()>0){
					TbCorpPerson fr = new TbCorpPerson();
					fr.setCorpId(corp.getId());
					fr.setPerMobile(this.corpBean.getCorpFrMobile());
					fr.setPerName(corpfr);
					fr.setPerPhone(this.corpBean.getCorpFrPhone());
					fr.setPerDegree(this.corpBean.getCorpFrDegree());
					fr.setPerTraining(this.corpBean.getCorpFrTraining());
					fr.setPerWorkingYear(this.corpBean.getCorpFrWorkingYear());
					fr.setPerEmail(this.corpBean.getCorpFrEmeail());
					fr.setPerType("1");
					this.utilService.save(fr);
				}
				String corpfzr = this.corpBean.getCorpFzr();//主要负责人
				if(null!=corpfzr && corpfzr.length()>0){
					TbCorpPerson fzr = new TbCorpPerson();
					fzr.setCorpId(corp.getId());
					fzr.setPerMobile(this.corpBean.getCorpFzrMobile());
					fzr.setPerName(corpfzr);
					fzr.setPerPhone(this.corpBean.getCorpFzrPhone());
					fzr.setPerSex(this.corpBean.getCorpFzrSex());
					fzr.setPerDegree(this.corpBean.getCorpFzrDegree());
					fzr.setPerTraining(this.corpBean.getCorpFzrTraining());
					fzr.setPerWorkingYear(this.corpBean.getCorpFzrWorkingYear());
					fzr.setPerEmail(this.corpBean.getCorpFzrEmeail());
					fzr.setPerType("2");
					this.utilService.save(fzr);
				}
				String corpaqr = this.corpBean.getCorpAqfzr();//安全负责人
				if(null!=corpaqr && corpaqr.length()>0){
					TbCorpPerson aqr = new TbCorpPerson();
					aqr.setCorpId(corp.getId());
					aqr.setPerMobile(this.corpBean.getCorpAqfzrMobile());
					aqr.setPerName(corpaqr);
					aqr.setPerType("3");
					aqr.setPerPhone(this.corpBean.getCorpAqfzrPhone());
					aqr.setPerSex(this.corpBean.getCorpAqfzrSex());
					aqr.setPerDegree(this.corpBean.getCorpAqfzrDegree());
					aqr.setPerTraining(this.corpBean.getCorpAqfzrTraining());
					aqr.setPerWorkingYear(this.corpBean.getCorpAqfzrWorkingYear());
					aqr.setPerEmail(this.corpBean.getCorpAqfzrEmeail());
					this.utilService.save(aqr);
				}
				this.setTip("添加成功！");
				return this.list();
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("enterprise: CorpTwoAction:saveOrUpdate() 异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 保存企业基础信息
	 * @param corp
	 * @return
	 */
	public TbCorpInfo saveCorp(TbCorpInfo corp){
		try {
//			corp.setCorpAqrs(Integer.parseInt(this.corpBean.getCorpAqrs()));//安全人数
//			corp.setCorpChanpin(this.corpBean.getCorpChanpin());//产品
//			corp.setCorpCyrs(Integer.parseInt(this.corpBean.getCorpCyrs()));//从业人数
//			corp.setCorpDishang(Double.parseDouble(this.corpBean.getCorpDishang()));//地上面积
//			corp.setCorpDixia(Double.parseDouble(this.corpBean.getCorpDixia()));//地下面积
//			corp.setCorpDixiayongtu(this.corpBean.getCorpDixiayongtu());//地下用途
//			corp.setCorpEmail(this.corpBean.getCorpEmail());//
//			corp.setCorpGsCode(this.corpBean.getCorpGsCode());//工商注册号
//			if(null!=this.corpBean.getCorpGudingzichang() && this.corpBean.getCorpGudingzichang().length()>0){
//				corp.setCorpGudingzichang(Double.parseDouble(this.corpBean.getCorpGudingzichang()));//
//			}
			corp.setCorpStatus(this.corpBean.getCorpStatus());//企业状态
			corp.setCorpIsDanger(this.corpBean.getCorpIsDanger());//是否含有重大危险源
			corp.setCorpDanger(this.corpBean.getCorpDanger());
			corp.setCorpIsShewei(this.corpBean.getCorpIsShewei());//是否含有涉及危化品使用
			corp.setCorpShewei(this.corpBean.getCorpShewei());
			corp.setCorpIsZyb(this.corpBean.getCorpIsZyb());//是否有职业病
			corp.setCorpZyb(this.corpBean.getCorpZyb());
			corp.setCorpIsTeshe(this.corpBean.getCorpIsTeshe());//是否有特种设备
			corp.setCorpTeshe(this.corpBean.getCorpTeshe());
			corp.setCorpIsBlzh(this.corpBean.getCorpIsBlzh());//是否有避雷装置
//			corp.setCorpJingyixiangmu(this.corpBean.getCorpJingyixiangmu());//经营项目
//			corp.setCorpLixu(this.corpBean.getCorpLixu());//隶属关系
			corp.setCorpLoginCount(0);
			corp.setCorpName(this.corpBean.getCorpName());//企业名称
			corp.setCorpOfficeAddress(this.corpBean.getCorpOfficeAddress());//办公地址
//			corp.setCorpOrgCode(this.corpBean.getCorpOrgCode());//组织机构代码
//			corp.setCorpPhone(this.corpBean.getCorpPhone());//
//			corp.setCorpPost(this.corpBean.getCorpPost());//邮编
//			corp.setCorpProperty(this.corpBean.getCorpProperty());//国民经济类型
//			corp.setCorpRegAddress(this.corpBean.getCorpRegAddress());//注册地址
//			corp.setCorpRegDate(DateFormater.formatDate(this.corpBean.getCorpRegDate()));//注册时间
//			String corpRegType = this.corpBean.getCorpRegType();//
//			if(corpRegType != null && !"".equals(corpRegType)){
//				corp.setCorpRegType(Long.parseLong(corpRegType));	//注册类型
//			}
//			corp.setCorpRenzhengxinxi(this.corpBean.getCorpRenzhengxinxi());//认证信息
			corp.setCorpReportType(this.corpBean.getCorpReportType());//自查自报类型
			corp.setCorpWorkAddress(this.corpBean.getCorpWorkAddress());//经营地址
//			corp.setCorpXkCode(this.corpBean.getCorpXkCode());//安全许可证号
//			String corpXkStart = this.corpBean.getCorpXkStart();	//认可起始时间
//			if(corpXkStart != null && !"".equals(corpXkStart)){
//				corp.setCorpXkStart(DateFormater.formatDate(corpXkStart));
//			}
//			String corpXkEnd = this.corpBean.getCorpXkEnd();//许可结束时间
//			if(corpXkEnd != null && !"".equals(corpXkEnd)){
//				corp.setCorpXkEnd(DateFormater.formatDate(corpXkEnd));
//			}
//			corp.setCorpYuanliao(this.corpBean.getCorpYuanliao());//原料
//			if(null!=this.corpBean.getCorpZhucezichang() && this.corpBean.getCorpZhucezichang().length()>0){
//				corp.setCorpZhucezichang(Double.parseDouble(this.corpBean.getCorpZhucezichang()));//注册资金
//			}
		} catch (Exception e) {
			Loggers.error("manager:CorpTwoAction:saveCorp()方法出错："+e.getMessage());
			e.printStackTrace();
		}
		return corp;
	}
	
	/**
	 * 企业信息查看
	 * @return
	 */
	public String look(){
		try {
			if(null!=this.corpId && this.corpId.length()>0){
				TbCorpInfo corp = this.enterprisService.getCorpById(corpId);
				if(null!=corp){
					this.setCorp(corp);
					this.setFzr(this.enterprisService.getCorpPer(this.corpId, "2"));
					this.setAqfzr(this.enterprisService.getCorpPer(this.corpId, "3"));
					this.setResult("corpTwo_look");
					return SUCCESS;
				}
			}
		} catch (Exception e) {
			Loggers.error("manager:CorpTwoAction:look()方法出错："+e);
			e.printStackTrace();
		}
		this.setTip(Util.NOTIP);
		return ERROR;
	}
	
	public String getQuaryHql(){
		TbUser user = (TbUser)this.contextPvd.getSessionAttr(Util.SESSION_ADMINUSER);
		String grade = user.getTbUserGrade().getId().toString();//用户级别
		TbUserDept unit = null;//用户单位
		TbUserDept dept = null;//用户部门
		if(null!=user.getTbUserUnit()){
			unit = user.getTbUserUnit();
		}
		if(null!=user.getTbUserDept()){
			dept = user.getTbUserDept();
		}
		StringBuilder urls = new StringBuilder("");
		StringBuilder hql = new StringBuilder(" where 1=1 ");
		String key = "";
		if(null!=this.cLixu && this.cLixu.length()>0){
			if(null!=this.getSearch() && "1".equals(this.getSearch())){
				this.cLixu = this.cLixu.trim();
			}else{
				this.cLixu = this.contextPvd.decode(this.getCLixu());	
			}
			hql.append(" and t.corpLixu like '%"+this.cLixu+"%'");
			urls.append("cLixu="+this.contextPvd.encode(this.cLixu));
		}else{
			urls.append("cLixu=");
		}
		if(null!=this.keyWord && this.keyWord.length()>0){
			if(null!=this.getSearch() && "1".equals(this.getSearch())){
				key = this.getKeyWord().trim();
			}else{
				key = this.contextPvd.decode(this.getKeyWord());	
			}
			this.setKeyWord(key);
			hql.append(" and t.corpName like '%"+key+"%'");
			urls.append("&keyWord="+this.contextPvd.encode(this.keyWord));
		}else{
			urls.append("&keyWord=");
		}
		
		if("3".equals(grade) && "3".equals(dept.getDeptClass())){//市科室行业部门
			hql.append(" and t.deptMainId="+dept.getId());
			urls.append("&cHy="+dept.getId().toString());
			this.setCHy(dept.getId().toString());
			/*if(null!=this.cMaxType && this.cMaxType.length()>0){
				hql.append(" and t.maxTypeId="+this.cMaxType);
				urls.append("&cMaxType="+this.cMaxType);
			}
			if(null!=this.cMinType && this.cMinType.length()>0){
				hql.append(" and t.minTypeId="+this.cMinType);
				urls.append("&cMinType="+this.cMinType);
			}*/
		}else if("4".equals(grade) && "3".equals(dept.getDeptClass())){//县区科室行业部门
			if((null==this.cMaxType || "".equals(this.cMaxType)) && (null==this.cMinType || "".equals(this.cMinType))){
				hql.append(" and t.quDeptIds like '%"+dept.getId()+"%'");
			}/*else{
				if(null!=this.cMaxType && this.cMaxType.length()>0){
					hql.append(" and t.maxTypeId="+this.cMaxType);
					urls.append("&cMaxType="+this.cMaxType);
				}
				if(null!=this.cMinType && this.cMinType.length()>0){
					hql.append(" and t.minTypeId="+this.cMinType);
					urls.append("&cMinType="+this.cMinType);
				}
			}*/
			if(null!=this.cHy && this.cHy.length()>0){
				hql.append(" and t.deptMainId="+this.cHy);
				urls.append("&cHy="+this.cHy);
			}
		}else if("5".equals(grade)){//市行业
			if("1".equals(unit.getDeptClass())){//行业监管
				hql.append(" and t.deptMainId="+unit.getId());
				urls.append("&cHy="+unit.getId().toString());
				this.setCHy(unit.getId().toString());
			}else{//专业监管
				if("5310".equals(unit.getId().toString())){//质监局
					hql.append(" and t.corpIsTeshe=1");
				}else if("5311".equals(unit.getId().toString())){//消防局
					
				}else if("5312".equals(unit.getId().toString())){//气象局
					hql.append(" and t.corpIsBlzh=1");
				}
				if(null!=this.cHy && this.cHy.length()>0){
					hql.append(" and t.deptMainId="+this.cHy);
					urls.append("&cHy="+this.cHy);
				}
			}
	/*		if(null!=this.cMaxType && this.cMaxType.length()>0){
				hql.append(" and t.maxTypeId="+this.cMaxType);
				urls.append("&cMaxType="+this.cMaxType);
			}
			if(null!=this.cMinType && this.cMinType.length()>0){
				hql.append(" and t.minTypeId="+this.cMinType);
				urls.append("&cMinType="+this.cMinType);
			}*/
		}else if("6".equals(grade)){//区行业
			if("1".equals(dept.getDeptClass())){
				hql.append(" and t.deptMainId="+dept.getDeptSj());
				urls.append("&cHy="+dept.getDeptSj().toString());
				this.setCHy(dept.getDeptSj().toString());
			}else{
				if("5310".equals(dept.getDeptSj().toString())){//质监局
					hql.append(" and t.corpIsTeshe=1");
				}else if("5311".equals(dept.getDeptSj().toString())){//消防局
					
				}else if("5312".equals(dept.getDeptSj().toString())){//气象局
					hql.append(" and t.corpIsBlzh=1");
				}
				if(null!=this.cHy && this.cHy.length()>0){
					hql.append(" and t.deptMainId="+this.cHy);
					urls.append("&cHy="+this.cHy);
				}
			}
		/*	if(null!=this.cMaxType && this.cMaxType.length()>0){
				hql.append(" and t.maxTypeId="+this.cMaxType);
				urls.append("&cMaxType="+this.cMaxType);
			}
			if(null!=this.cMinType && this.cMinType.length()>0){
				hql.append(" and t.minTypeId="+this.cMinType);
				urls.append("&cMinType="+this.cMinType);
			}*/
		}/*else{//其他用户
			if(null!=this.cMaxType && this.cMaxType.length()>0){
				hql.append(" and t.maxTypeId="+this.cMaxType);
				urls.append("&cMaxType="+this.cMaxType);
			}
			if(null!=this.cMinType && this.cMinType.length()>0){
				hql.append(" and t.minTypeId="+this.cMinType);
				urls.append("&cMinType="+this.cMinType);
			}
			if(null!=this.cHy && this.cHy.length()>0){
				hql.append(" and t.deptMainId="+this.cHy);
				urls.append("&cHy="+this.cHy);
			}
		}*/
		
		if("4".equals(grade) || "6".equals(grade) || "8".equals(grade)){//县区安委会、区科室、区行业
			hql.append(" and t.countyId="+unit.getId());
			this.setCCounty(unit.getId().toString());
			if(null!=this.cUnit && this.cUnit.length()>0){
				hql.append(" and t.unitId="+this.cUnit);
				urls.append("&cUnit="+this.cUnit);
			}
			if(null!=this.cDept && this.cDept.length()>0){
				hql.append(" and t.deptId="+this.cDept);
				urls.append("&cDept="+this.cDept);
			}
		}else if("7".equals(grade)){//属地
			hql.append(" and t.countyId="+unit.getId()+" and t.unitId="+dept.getId());
			this.setCCounty(unit.getId().toString());
			this.setCUnit(dept.getId().toString());
			if(null!=this.cDept && this.cDept.length()>0){
				hql.append(" and t.deptId="+this.cDept);
				urls.append("&cDept="+this.cDept);
			}
		}else{
			if(null!=this.cCounty && this.cCounty.length()>0){
				hql.append(" and t.countyId="+this.cCounty);
				urls.append("&cCounty="+this.cCounty);
			}
			if(null!=this.cUnit && this.cUnit.length()>0){
				hql.append(" and t.unitId="+this.cUnit);
				urls.append("&cUnit="+this.cUnit);
			}
			if(null!=this.cDept && this.cDept.length()>0){
				hql.append(" and t.deptId="+this.cDept);
				urls.append("&cDept="+this.cDept);
			}
		}
		if(null!=this.cMaxType && this.cMaxType.length()>0){
			hql.append(" and t.maxTypeId="+this.cMaxType);
			urls.append("&cMaxType="+this.cMaxType);
		}
		if(null!=this.cMinType && this.cMinType.length()>0){
			hql.append(" and t.minTypeId="+this.cMinType);
			urls.append("&cMinType="+this.cMinType);
		}
		if(null!=this.cHy && this.cHy.length()>0){
			hql.append(" and t.deptMainId="+this.cHy);
			urls.append("&cHy="+this.cHy);
		}
		if(null!=this.cZcType && this.cZcType.length()>0){
			hql.append(" and t.corpReportType="+this.cZcType);
			urls.append("&cZcType="+this.cZcType);
		}
		hql.append(" and t.isDele=0 and t.corpSize=2");
		this.setUrls(urls.toString());
		return hql.toString();
	}
	
	public CorpBean getCorpBean() {
		return corpBean;
	}

	public void setCorpBean(CorpBean corpBean) {
		this.corpBean = corpBean;
	}

	public CorpBean getModel() {
		return this.corpBean;
	}

	public TbCorpPerson getAqfzr() {
		return aqfzr;
	}

	public void setAqfzr(TbCorpPerson aqfzr) {
		this.aqfzr = aqfzr;
	}

	public TbCorpPerson getFzr() {
		return fzr;
	}

	public void setFzr(TbCorpPerson fzr) {
		this.fzr = fzr;
	}

	public String getAqfzrId() {
		return aqfzrId;
	}

	public void setAqfzrId(String aqfzrId) {
		this.aqfzrId = aqfzrId;
	}

	public String getFzrId() {
		return fzrId;
	}

	public void setFzrId(String fzrId) {
		this.fzrId = fzrId;
	}

}
